<template>
    <div>

        <!--顶栏-->
        <el-row>
            <el-col :span="24" class="title_area">
                <h4>统计</h4>
                <el-breadcrumb separator="/">
                    <el-breadcrumb-item :to="{ path: '/indexpage' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>书籍列表</el-breadcrumb-item>
                </el-breadcrumb>
            </el-col>
        </el-row>

        <el-row>
            <span>今日收入</span>:{{ today_income }}
        </el-row>

        <!--列表日流水-->
        <el-table :data="tableDataDayFlow"  border style="width: 100%;margin-top: 20px">
            <el-table-column label="每日流水">
                <el-table-column prop="purchase_number" label="订单号"></el-table-column>
                <el-table-column prop="total_amount" label="总金额"></el-table-column>
                <el-table-column prop="real_pay" label="实际支付金额"></el-table-column>
                <el-table-column prop="pay_at" label="支付时间"></el-table-column>
                <el-table-column label="是否使用优惠券" >
                    <template scope="scope">
                        <span v-if="scope.row.customer_coupon_id > 0 ">使用优惠券</span>
                        <span v-else>未使用优惠券</span>
                    </template>
                </el-table-column>
            </el-table-column>
        </el-table>

        <!--列表按月-->
        <el-table :data="tableDataMonth"  border style="width: 100%;margin-top: 20px">
            <el-table-column label="月份收益">
                <el-table-column prop="month" label="月份"></el-table-column>
                <el-table-column prop="total_income_month" label="总收入"></el-table-column>
            </el-table-column>
        </el-table>

        <!--列表按年-->
        <el-table :data="tableDataYear"  border style="width: 100%;margin-top: 20px">
            <el-table-column label="年份收益">
                <el-table-column prop="year" label="月份"></el-table-column>
                <el-table-column prop="total_income_year" label="总收入"></el-table-column>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>

  export default {
    data() {
      return {
        options: [{
          value: 'price',
          label: '原价'
        }, {
          value: 'discount',
          label: '折扣价'
        }, {
          value: 'score',
          label: '评分'
        }],
        prop: '',
        className:'right',
        tableDataMonth:[],
        tableDataYear:[],
        tableDataDayFlow:[],
        today_income: 0,
        title: '',
        author: '',
        start: '',
        end: '',
        pagination: {
          total: 20,
          count: 20,
          current_page: 1,
          total_pages: 1
        },
        total_pages: 100
      }
    },
    components: {

    },

    created() {
        this.statisticDayIncome()
        this.statisticMonthIncome()
        this.statisticYearIncome()
        this.staticsDayFlow()
    },

    methods: {

      shelfeBook(index, table) {
        var id = table[index].id
        let params = {
          id: id
        }
        this.$store.dispatch('shelfBook', params).then((ret) => {
          if(ret.success) {
            this.$notify({
              title: '成功',
              message: '书籍上架成功',
              type: 'success'
            });
            this.bookList()
          }else{
            this.$notify({
              title: '失败',
              message: '修改状态失败',
              type: 'error'
            });
          }
        })

      },

      relationBookBookCategory(index, table) {
        var id = table[index].id
        this.$router.push({name: 'addBookBookCategory', params: {id: id}})
      },


      changeRight(value) {
        this.className = value
      },

      statisticDayIncome() {
        this.$store.dispatch('statisticDayIncome').then((ret) => {
          this.today_income = ret.data.day_income
        })
      },

      statisticMonthIncome() {
        this.$store.dispatch('statisticMonthIncome').then((ret) => {
         this.tableDataMonth  = ret.data.month
        })
      },

      statisticYearIncome() {
        this.$store.dispatch('statisticYearIncome').then((ret) => {
          this.tableDataYear = ret.data.year
        })
      },

      staticsDayFlow() {
        this.$store.dispatch('staticsDayFlow').then((ret) => {
          this.tableDataDayFlow = ret.data.dayFlow
        })
      }

    }
  }
</script>
<style scoped>
    .header { background: #f2f2f2; }
</style>
